/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sghfim;

import Atributos.at_tela;
import BD.CriaConexao;
import Formularios.Apresentacao;
import Formularios2.Apresentacao2;
import Formularios2.Menu3;
import Metodos.CursoMet;
import Metodos.MinimizaTela;
import Metodos.ObjetoMet;
import Metodos.tela;
import java.awt.Desktop;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;


/**
 *
 * @author Andre
 */
public class ChavedeSeguranca extends javax.swing.JFrame {
private Connection conexao;
ObjetoMet objmet =new ObjetoMet();
    /**
     * Creates new form ChavedeSeguranca
     */
    public ChavedeSeguranca() {
       
            try {
               for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                   if ("Windows".equals(info.getName())) {
                       javax.swing.UIManager.setLookAndFeel(info.getClassName());
                       break;
                   }
               }
           } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
               java.util.logging.Logger.getLogger(ChavedeSeguranca.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
           }
           initComponents();
            try {
               this.conexao=(Connection) CriaConexao.getConexao();
           } catch (SQLException ex) {
               Logger.getLogger(CursoMet.class.getName()).log(Level.SEVERE, null, ex);
           }
            if(VerificaDATA() || VerificaDATA2()){
                this.setVisible(true);
            }else{
               ChamaMetodo();
               dispose();
            }
           BufferedImage image=null;
        File imageFile=new File(".\\src\\Imagens\\sghverde3.png");
        try {
            image=ImageIO.read(imageFile);
            
        } catch (IOException ex) {
        }
        this.setIconImage(image);
           jLabel3.setVisible(false);
          
             
//            String sql = "CREATE ROLE EEEP2 NOINHERIT LOGIN PASSWORD '123'";
//               PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql);
//                   
//                   consulta.execute();
//                   consulta.close();
//        } catch (SQLException ex) {
//            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        try{  
//ProcessBuilder pb;  
//Process p;  
//pb = new ProcessBuilder("C:/Program Files/PostgreSQL/9.1/bin/pg_dump.exe ", "-i", "-h", "localhost", "-p", "5432","-U", "postgres", "-F", "c", "-b", "-v" ,"-f", "C:\\Users\\MARK\\Desktop\\sghpost.sql", "sgh");  
//pb.environment().put("postgres", "123");  
//pb.redirectErrorStream(true);  
//p = pb.start();   
//}catch(Exception ex){  
//    JOptionPane.showMessageDialog(null, ex);  
//}  

        
   }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Validar Software");
        setResizable(false);
        getContentPane().setLayout(null);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("Validar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(110, 130, 98, 34);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Obter Chave");
        jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel1);
        jLabel1.setBounds(220, 185, 78, 17);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Insira a chave de segurança");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(70, 30, 170, 17);

        jLabel3.setForeground(new java.awt.Color(255, 0, 0));
        jLabel3.setText("Chave Invalida");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(120, 100, 90, 14);

        jTextField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        getContentPane().add(jTextField1);
        jTextField1.setBounds(30, 70, 250, 23);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-329)/2, (screenSize.height-253)/2, 329, 253);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         Date hoje = new Date(); 
                           SimpleDateFormat dfdia,dfmes,dfano; 
                           dfdia = new SimpleDateFormat("dd"); 
                           dfmes = new SimpleDateFormat("MM"); 
                           dfano = new SimpleDateFormat("yyyy"); 
                           String dia2,mes2,ano2;
                           int dia,mes,ano;
                           dia2=dfdia.format(hoje);
                           mes2=dfmes.format(hoje);
                           ano2=dfano.format(hoje);
                           dia=Integer.valueOf(dia2);
                           mes=Integer.valueOf(mes2);
                           ano=Integer.valueOf(ano2); 
             String sql3 = "update seguranca set dia=?,mes=?,ano=? where chave=?";
                  try {
                 String sql = "select chave from seguranca";
                 PreparedStatement stmt = (PreparedStatement) conexao.prepareStatement(sql);
                 ResultSet rs = stmt.executeQuery();
                     while (rs.next()) {   
                       
                 
                        if(ano==2012 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+123416))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-123416);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2013 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*2))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*2);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2014 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*3))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*3);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2015 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*4))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*4);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2016 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*5))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*5);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2017 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*6))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*6);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2018 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*7))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*7);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2019 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*8))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*8);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2020 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*9))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*9);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2021 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*10))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*10);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2022 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*11))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*11);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2023 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*12))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*12);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2024 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*13))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*13);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2025 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*14))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*14);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2026 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*15))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*15);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2027 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*16))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*16);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2028 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*17))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*17);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2029 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*18))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*18);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2030 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*19))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*19);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2031 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*20))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*20);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2032 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*21))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*21);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2033 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*22))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*22);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2034 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*23))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*23);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2035 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*24))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*24);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2036 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*25))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*25);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        if(ano==2037 && jTextField1.getText().equals(String.valueOf(rs.getLong("chave")+(123416)*26))){
                                            try{
                                            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql3)) {
                                                
                                                if(dia==29 && mes==2){
                                                consulta.setInt(1, dia-1);
                                                }else{
                                                consulta.setInt(1, dia);    
                                                }
                                                consulta.setInt(2, mes);
                                                consulta.setInt(3, ano);
                                                consulta.setLong(4, Long.parseLong(jTextField1.getText())-(123416)*26);
                                                consulta.execute();
                                            }

                                        }catch(SQLException ex){
                                            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                                        }  
                                                                ChamaMetodo();         
                                        }
                        
                                        
                        
                        else{
                                            jLabel3.setVisible(true);
                                        }
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                     }
                    } catch (SQLException ex) {
                        Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
                    }
                     
          
            

                    
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
      
        // código para abrir a página  
                Desktop desktop = null;       
                //Primeiro verificamos se é possível a integração com o desktop       
                if (!Desktop.isDesktopSupported())       
                    throw new IllegalStateException("Desktop resources not supported!");       
  
                desktop = Desktop.getDesktop();       
                //Agora vemos se é possível disparar o browser default.       
                if (!desktop.isSupported(Desktop.Action.BROWSE))       
                    throw new IllegalStateException("No default browser set!");       
  
                //Pega a URI de um componente de texto.       
                URI uri = null;    
                try {    
                    uri = new URI("http://www.google.com.br");    
                } catch (URISyntaxException e1) {    
                    e1.printStackTrace();    
                }       
  
                //Dispara o browser default, que pode ser o Explorer, Firefox ou outro.       
                try {    
                    desktop.browse(uri);    
                } catch (IOException e) {    
                    e.printStackTrace();    
                }    
  
              
             
    }//GEN-LAST:event_jLabel1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
       
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ChavedeSeguranca().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

    private void ChamaMetodo() {
        tela a = null;
        try {
            a = new tela();
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(SGHfim.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            a.buscar();
        } catch (SQLException ex) {
            Logger.getLogger(SGHfim.class.getName()).log(Level.SEVERE, null, ex);
        }
       
 at_tela b= new at_tela();
        
int c=b.getNumero();       
if(c==1){
MinimizaTela tela= new MinimizaTela(); 
        try {
            tela.Minimiza(0);
        } catch (SQLException ex) {
            Logger.getLogger(SGHfim.class.getName()).log(Level.SEVERE, null, ex);
        }
       java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Apresentacao().setVisible(true);
            }
        });         
       
                 
}

if(c==2){
    int quantresg;
ObjetoMet objmet=new ObjetoMet();
            try {
                quantresg=objmet.QuatRegistro();
            } catch (SQLException ex) {
                Logger.getLogger(SGHfim.class.getName()).log(Level.SEVERE, null, ex);
            }
    if(objmet.HouverDados()){
          java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Apresentacao2().setVisible(true);
            }
        }); 
        }else{
                try {
                    objmet.DeletarTabHorarioTabRelProf();
                } catch (SQLException ex) {
                    Logger.getLogger(SGHfim.class.getName()).log(Level.SEVERE, null, ex);
                }
            java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Menu3().setVisible(true);
            }
        }); 
            
        }
    
    
   
}
dispose();
    }
    private  boolean VerificaDATA() {
        int dia=0;
        try {                                         
           
            String sql2 = "select dia from seguranca";
            PreparedStatement stmt2 = (PreparedStatement) conexao.prepareStatement(sql2);
                 ResultSet rs2 = stmt2.executeQuery();
                     while (rs2.next()) {   
                         dia=rs2.getInt("dia");
                     }
                             
        } catch (SQLException ex) {
            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
        }
           if(dia==0){
             return true;  
           }else{
             return false;  
           }
    }
    
    private  boolean VerificaDATA2() {
        int dia3 = 0,mes3 = 0,ano3 = 0;
        try {                                         
           
            String sql2 = "select dia,mes,ano from seguranca";
            PreparedStatement stmt2 = (PreparedStatement) conexao.prepareStatement(sql2);
                 ResultSet rs2 = stmt2.executeQuery();
                     while (rs2.next()) {   
                         dia3=rs2.getInt("dia");
                         mes3=rs2.getInt("mes");
                         ano3=rs2.getInt("ano");
                     }
                             
        } catch (SQLException ex) {
            Logger.getLogger(ChavedeSeguranca.class.getName()).log(Level.SEVERE, null, ex);
        }
        Date hoje = new Date(); 
                           SimpleDateFormat dfdia,dfmes,dfano; 
                           dfdia = new SimpleDateFormat("dd"); 
                           dfmes = new SimpleDateFormat("MM"); 
                           dfano = new SimpleDateFormat("yyyy"); 
                           String dia2,mes2,ano2;
                           int dia,mes,ano;
                           dia2=dfdia.format(hoje);
                           mes2=dfmes.format(hoje);
                           ano2=dfano.format(hoje);
                           dia=Integer.valueOf(dia2);
                           mes=Integer.valueOf(mes2);
                           ano=Integer.valueOf(ano2);

                           if(ano3<ano){
                               if(mes3<=mes){
                                   if(dia3<dia){
                                       return true;
                                   }else{
                                       return false;
                                   }
                               }else{
                                   return false;
                               }
                           }else{
                               return false;
                           }
    }
}
